
package com.gp.activity.detail;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

import com.gp.R;
import com.gp.activity.base.BaseActivity;

public class SelfGuideDetailActivity extends BaseActivity {

    private Holder mHolder = new Holder();
    // 展现地图的按钮
    private Button mLocButton;
    
    private int mLocation;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.selfguide_detail);

        initView();
        getData();
        bindData();
        initListener();

    }

    private void initView() {

        mLocButton = (Button) findViewById(R.id.bnt_sight_loc);

        mHolder.mSight_ima = (ImageView) findViewById(R.id.iv_sight_de_ima);
        mHolder.mSight_name = (TextView) findViewById(R.id.tv_sight_de_name);
        mHolder.mSight_type = (TextView) findViewById(R.id.tv_sight_de_type);
        mHolder.mSight_level = (RatingBar) findViewById(R.id.rb_sight_de_level);
        mHolder.mSight_price = (TextView) findViewById(R.id.tv_sight_de_price);
        mHolder.mSight_opentime = (TextView) findViewById(R.id.tv_sight_de_opentime);
        mHolder.mSight_phone = (TextView) findViewById(R.id.tv_sight_de_phone);
        mHolder.mSight_des = (TextView) findViewById(R.id.tv_sight_de_des);
    }

    private void getData() {

        // 用Bundle来接受数据
        Bundle qBundle = getIntent().getExtras();

        mHolder.mImaID = qBundle.getInt("imaID");
        mHolder.mName = qBundle.getString("name");
        mHolder.mType = qBundle.getString("type");
        mHolder.mLevel = qBundle.getInt("level");
        mHolder.mPrice = qBundle.getInt("price");
        mHolder.mOpenTime = qBundle.getString("opentime");
        mHolder.mPhone = qBundle.getString("phone");
        mHolder.mDes = qBundle.getString("des");
        mLocation = qBundle.getInt("location");
    }

    private void bindData() {

        mHolder.mSight_ima.setImageResource(mHolder.mImaID);
        mHolder.mSight_name.setText(mHolder.mName);
        mHolder.mSight_type.setText(mHolder.mType);
        mHolder.mSight_level.setNumStars(mHolder.mLevel);
        mHolder.mSight_level.setRating(mHolder.mLevel);
        if (mHolder.mPrice != 0) {

            mHolder.mSight_price.setText(String.valueOf(mHolder.mPrice));
        }
        else {
            mHolder.mSight_price.setText("免费");
        }
        mHolder.mSight_opentime.setText(mHolder.mOpenTime);
        mHolder.mSight_phone.setText(mHolder.mPhone);
        mHolder.mSight_des.setText(mHolder.mDes);
    }

    private void initListener() {
        mLocButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent qIntent = new Intent();
                qIntent.setClass(SelfGuideDetailActivity.this,
                        SightMapActivity.class);
                qIntent.putExtra("location", mLocation);
                SelfGuideDetailActivity.this.startActivity(qIntent);
            }
        });
    }

    private static class Holder {
        // 显示数据的控件
        ImageView mSight_ima;
        TextView mSight_name;
        TextView mSight_type;
        RatingBar mSight_level;
        TextView mSight_price;
        TextView mSight_opentime;
        TextView mSight_phone;
        TextView mSight_des;

        // 接受数据
        int mImaID;
        String mName;
        String mType;
        int mLevel;
        int mPrice;
        String mOpenTime;
        String mPhone;
        String mDes;

    }
}
